package com.example.t410.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.t410.model.AnsReturn;
import com.example.t410.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/manage")
public class manageController {

    @Autowired
    private TopicService topicService;
    JSONObject jsonObject = new JSONObject();

    //查询全部
    @GetMapping("/getAll")
    public JSONObject getAll() {
        jsonObject.clear();
        jsonObject.put("status", 200);
        jsonObject.put("data", topicService.findAll());
        return jsonObject;
    }
    @PostMapping("/submit")
    public JSONObject calculateAns(@RequestBody JSONObject object) {
        jsonObject.clear();
        String ans = object.getString("ans");
        AnsReturn ans1 = topicService.calculateAns(ans);
        if (ans1 != null) {
            jsonObject.put("status", 200);
            jsonObject.put("data", ans1);
        } else {
            jsonObject.put("status", 201);
            jsonObject.put("data", null);
        }
        return jsonObject;

    }
}
